#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int W, H;
const int MAXN = 21;
int board[MAXN][MAXN];
int sx, sy, ex, ey;
bool success;
int moves = 12;
void solve();

int main() {
    while (cin >> W >> H && W + H != 0) {
        success = false;
        moves = 12;
        memset(board, 0, sizeof board);
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> board[i][j];
                if (board[i][j] == 2) {
                    sx = i; sy = j;
                }
                if (board[i][j] == 3) {
                    ex = i; ey = j;
                }
            }
        }
        solve();
    }
}

int dxdy[][4] = {
    {1, -1, 0, 0},
    {0, 0, 1, -1}
};

void dfs(int x, int y, int ops) {
    if (ops > 10) return;
    ops += 1; // 挥拍
    for (int i = 0; i < 4; i++) {
        int dx = dxdy[0][i], dy = dxdy[1][i];
        int xx = x, yy = y;
        while (true) {
            xx += dx; yy += dy;

            if (xx == ex && yy == ey) {
                success = true;
                moves = min(ops, moves);
            }

            if (xx < 0 || xx >= H || 
                yy < 0 || yy >= W) 
                break;

            if (board[xx][yy] == 1) {
                if (xx - dx == x && yy - dy == y) break; // 相当于原地被阻碍
                board[xx][yy] = 0;
                dfs(xx - dx, yy - dy, ops);
                board[xx][yy] = 1;
                break;
            }
        }
    } 
}


void solve() {
    dfs(sx, sy, 0);
    if (success && moves <= 10) cout << moves << endl;
    else cout << -1 << endl;
}